<extend name="Public/baseConf"/>
<block name="breadcrumb"> 
	<div class="row wrapper border-bottom white-bg page-heading">
	    <div class="col-lg-6">
	        <h2><present name="data">还原数据库</h2>
	        <ol class="breadcrumb">
	            <li><a href="{:U('index/index')}">首页</a></li>
	            <li class="active">
	                <strong>还原数据库</strong>
	            </li>
	        </ol>
	    </div>
	</div>
</block>
<block name="body">
	<div class="row">
            <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>数据备份列表</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                    <form id="export-form" method="post" action="{:U('export')}">
		                  <table class="table table-striped table-bordered table-hover dataTables-example" >
			                  <thead>
			                  <tr>
			                    <th width="200">备份名称</th>
			                    <th width="80">卷数</th>
			                    <th width="80">压缩</th>
			                    <th width="80">数据大小</th>
			                    <th width="200">备份时间</th>
			                    <th>状态</th>
			                    <th width="120">操作</th>
			                  </tr>
			                  </thead>
			                  <tbody>
				                <volist name="list" id="data">
				                    <tr>
				                        <td>{$data.time|date='Ymd-His',###}</td>
				                        <td>{$data.part}</td>
				                        <td>{$data.compress}</td>
				                        <td>{$data.size|format_bytes}</td>
				                        <td>{$key}</td>
				                        <td>-</td>
				                        <td class="action">
				                            <a class="db-import" href="{:U('import?time='.$data['time'])}">还原</a>&nbsp;
				                            <a class="ajax-get confirm" href="{:U('del?time='.$data['time'])}">删除</a>
				                        </td>
				                    </tr>
				                </volist>
			                  </tbody>
		                  </table>
		            </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</block>

<block name="script">
    <script type="text/javascript">
        $(".db-import").click(function(){
            var self = this, status = ".";
            $.get(self.href, success, "json");
            window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
            return false;
        
            function success(data){
                if(data.status){
                    if(data.gz){
                        data.info += status;
                        if(status.length === 5){
                            status = ".";
                        } else {
                            status += ".";
                        }
                    }
                    $(self).parent().prev().text(data.info);
                    if(data.part){
                        $.get(self.href, 
                            {"part" : data.part, "start" : data.start}, 
                            success, 
                            "json"
                        );
                    }  else {
                        window.onbeforeunload = function(){ return null; }
                    }
                } else {
                    updateAlert(data.info,'alert-error');
                }
            }
        });
    </script>
</block>